// 封装get请求	
export const baseUrl = "http://bodexiong.vip:2103"
export const myRequest = (options)=>{
	return new Promise((resolve,reject)=>{
		uni.request({
			method: options.method,
			data: options.data,
			url: baseUrl+options.url,
			success(res) {
				// console.log(res.data)
				// if(res.data.status !== 200) {
				// 	return uni.showToast({
				// 		title: '获取数据失败'
				// 	})
				// }
				resolve(res)
			},
			fail(err) {
				uni.showToast({
					title: '获取数据失败',
					icon: 'none',
				})
				reject(err)
			}
		})
	})
}

export function get_keyname_value(data, key_name){
	var n = data.length
	var values = []
	for(var i = 0; i < n; i++){
		var dc = {
			"k": i,
			"v": data[i][key_name]
		}
		values.push(data[i][key_name])
		// values.push(dc)
	}
	// console.log('_______ values: ' + values)
	return values
}

export function add_hostname_before_keyname(data, keyname, new_keyname=''){
	if (new_keyname == ''){
		new_keyname = 'host_' + keyname
	}
	
	for(var i = 0; i < data.length; i++){
		 data[i][new_keyname] = baseUrl + data[i][keyname]
		 // console.log(data[i][new_keyname])
	}
					
	return data
}


	
export const get_v_by_kname = (options)=>{
	
	return new Promise( (resolve,reject)=>{
		
		get_keyname_value({
			data: options.data,
			key_name: options.key_name,
			success(res) {
				console.log('~~~ res ~~~')
				console.log(res)
				resolve(res)
			},
			fail(err) {
				uni.showToast({
					title: '获取数据失败'
				})
				reject(err)
			}
		})
	})
	

}




